package cn.kgc.itrip.controller;

import cn.kgc.itrip.common.DtoUtil;
import cn.kgc.itrip.dto.Dto;
import cn.kgc.itrip.service.linkUserService.UserInfoService;
import cn.kgc.itrip.vo.userinfo.ItripAddUserLinkUserVO;
import cn.kgc.itrip.vo.userinfo.ItripModifyUserLinkUserVO;
import cn.kgc.itrip.vo.userinfo.ItripSearchUserLinkUserVO;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * @program: love_travel
 * @description: 增删改查联系人
 * @author: Mr.Wang
 * @create: 2020-03-27 15:27
 **/


@RestController
@RequestMapping("/api/userinfo")
public class UserInfoController {

    @Resource
    private UserInfoService userInfoService;

    /**
     * 增加联系人
     * @param itripAddUserLinkUserVO
     * @return
     */
    @PostMapping(value = "/adduserlinkuser",consumes = "application/json",produces = "application/json")
    public Dto addUserLinkUser(@RequestBody ItripAddUserLinkUserVO itripAddUserLinkUserVO, HttpServletRequest request){
        Dto dto=null;
        try {
            dto= userInfoService.addUserLink(itripAddUserLinkUserVO,request);
        } catch (Exception e) {
            e.printStackTrace();
            return DtoUtil.returnFail("false","100411");
        }
        return dto;
    }

    /**
     * 删除联系人,未完成
     * @param ids
     * @param request
     * @return
     */
    @GetMapping(value = "/deluserlinkuser",produces = "application/json",consumes = "application/json")
    public Dto delUserLinkUser(@RequestBody Integer ids,HttpServletRequest request){
        Dto dto=null;
        String token = request.getHeader("token");
        try {
            dto=userInfoService.delLinkuser(ids,token);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return dto;
    }

    /**
     * 查询联系人
     * @param itripSearchUserLinkUserVO
     * @param request
     * @return
     */
    @PostMapping(value = "/queryuserlinkuser",consumes = "application/json",produces = "application/json")
    public Dto queryUserLinkUser(@RequestBody ItripSearchUserLinkUserVO itripSearchUserLinkUserVO
    ,HttpServletRequest request){
        Dto dto=null;
        String token = request.getHeader("token");
        dto=userInfoService.findLinkUser(itripSearchUserLinkUserVO,token);
        return dto;
    }

    /**
     * 修改联系人
     * @param itripModifyUserLinkUserVO
     * @param request
     * @return
     */
    @PostMapping(value = "/modifyuserlinkuser",consumes = "application/json",produces = "application/json")
    public Dto modifyUserLinkUser(@RequestBody ItripModifyUserLinkUserVO itripModifyUserLinkUserVO,HttpServletRequest request){
        Dto dto=null;
        String token = request.getHeader("token");
        try {
            dto=userInfoService.modUserLinkUser(token,itripModifyUserLinkUserVO);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return dto;
    }
}
